
             
/**
 * Copyright (c) 2012-2013 JLLT Corp. 2012-2013,All Rights Reserved.
 * This software is published under the 金麟龙腾商贸有限公司.
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file.
 *
 * @File name:  AddTProductCommentAction.java   添加【会员商品评论信息:T_PRODUCT_COMMENT】
 * @Create on:  2012-10-27 19:50:206
 * @Author   :  陈伟
 *
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */
           
        
package com.boho.ecp.member.action;

            
import java.sql.Connection;
import java.util.Date;

import org.apache.commons.lang.StringUtils;

import cn.boho.framework.actions.ActionImp;
import cn.boho.framework.context.ActionContext;
import cn.boho.framework.exception.UserOperationException;
import cn.boho.framework.po.DynaBeanMap;
import cn.boho.framework.po.POUtils;
import cn.boho.framework.service.MessageService;
import cn.boho.framework.utils.HTMLFilter;

import com.boho.ecp.constant.Comment;
import com.boho.ecp.constant.Member;
import com.boho.ecp.po.TProductCommentPO;
import com.boho.ecp.product.service.ProductService;

public class AddTProductCommentAction extends ActionImp {
	private TProductCommentPO tProductCommentPO = new TProductCommentPO();
	private Connection con=null;
	@Override
	protected void doException(ActionContext atx, Exception ex) {
		if (!(ex instanceof UserOperationException)) {
			atx.setErrorContext("BOHO_COMMON_1001", MessageService.getMessage("BOHO_COMMON_1001"),"【会员商品评论信息】", ex);
		}
	}
	@Override
	protected int performExecute(ActionContext atx) throws Exception {
		con = atx.getConection();
		Date date = new Date();
		DynaBeanMap dbm = (DynaBeanMap)atx.getSessionValue(Member.MEMBER_SESSEION);
		Integer memberId = (Integer)dbm.get("MEMBER_ID");
		String memberName = (String)dbm.get("MEMBER_ACCOUNT");
		Integer productId = atx.getIntegerValue("PRODUCT_ID");
		String comment = HTMLFilter.filter(atx.getStringValue("COMMENT_TEXT",""));
		if(StringUtils.isBlank(comment)){
			comment = "好评！";
		}
		tProductCommentPO.setMemberId(memberId);
		tProductCommentPO.setMemberAccount(memberName);
		tProductCommentPO.setProductId(productId);
		tProductCommentPO.setScore(atx.getStringValue("SCORE"));
		tProductCommentPO.setCommentText(comment);
		tProductCommentPO.setIsPass(Comment.WAIT);
		tProductCommentPO.setCommentDate(date);
		tProductCommentPO.setCreateBy(memberId.toString());
		tProductCommentPO.setCreateDate(date);
		POUtils.insert(con, tProductCommentPO,false);
		
		ProductService.updateReturnByProductId(con, productId);
		return 1;
	}
	@Override
	protected int verifyParameters(ActionContext atx) throws Exception {
		return 1;
	}
}
